package com.tanhao.takeaway.commom;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;

import java.time.LocalDateTime;

@Component
@Slf4j
public class MyMetaObjectHandle implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {


        log.info(String.valueOf(metaObject));
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("createUser",BaseContext.getThreadLocalId());
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("updateUser",BaseContext.getThreadLocalId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //log.info(BaseContext.getThreadLocalId().toString());
        long id = Thread.currentThread().getId();
        log.info("线程id为：{}",id);

//        metaObject.setValue("createTime", LocalDateTime.now());
//        metaObject.setValue("createUser",BaseContext.getThreadLocalId());
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("updateUser",BaseContext.getThreadLocalId());
    }
}
